|
Multi-lined text displaying Let us revert to the previous example with fishes. In the "Biolife.db" table, there is a "Notes" field, which contains a detailed description of each fish. Let us update our report by adding this field into it. At first sight, everything seems to be easy: add the "Text" object to the band with data, connect it to the "Notes" field and set the object’s size (8x2.5 cm). If starting the report, you will see that we receive not exactly what we expected:
However, FastReport performed just what he was asked to. The "Notes" field contains a multi-lined text, size of which may vary. At the same time, the "Text" object, which displays the information from this field, has fixed sizes. That is why some lines could not place the object and were cut. What should be done in such situation? Of course, either sizes of the window can be specified "in reserve," or font size can be reduced. However, this may lead to the uneconomical usage of space on the page, due to the fact that some fishes have long descriptions, while others have short ones. In FastReport, there are resources, which allow solving this problem. The matter concerns the band’s ability to automatically adjust its height in order to find room for all included objects. To perform this, we just need to enable the "Stretch" property. However, that is not all, because an object with a longer description should be able to stretch by itself. The "Text" object is able to manage it. The object can automatically set its height and width in order to find room for the whole text it contains. One can use the "AutoWidth" and "StretchMode" properties to perform this. The "AutoWidth" property selects the object width in a way, which allows all the lines find room without division of words. This mode is convenient when an object has a single text line. The "Stretch" property allows to select the object’s height in a way that the whole text finds room. The object width is not being changed during it. This property performs listing, and you can select one of the modes in the object inspector: smDontStretch – do not stretch an object, by default; Now we are interested in the "Stretch" property of the "Text" object. Enable it in the object context menu or set the "StretchMode = smActualHeight" property value. Also, enable the "Stretch" band property. Start the report and make sure that everything works in a proper way now.
As you can see, when constructing a report, FastReport fills objects with data, stretches them with the "Stretch" option enabled, and then collates band’s height in order to find room for all the objects. If the band "Stretch" option is disabled, the height setting is not performed, and the band is displayed according to height specified in the designer. If we try to disable this option, we would see that the objects with longer texts are still stretched, although bands are not. That leads to text overlaying, since each next band is displayed right after the previous one. |